<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript" language="javascript" src="/js/jquery-1.6.1.min.js"></script>
	<script type="text/javascript" language="javascript" src="/js/tool.js"></script>
	<title>琥珀川 - 管理员登陆</title>
</head>

<body>
	<div class="mainDiv">
		<table border="1">
			<tr>
				<td>用户名:</td>
				<td>
					<input id="userName" type="text" value="" style="width:200px;"/>
				</td>
			</tr>
			<tr>
				<td>密码:</td>
				<td>
					<input id="userPass" type="password" value="" style="width:200px;"/>
				</td>
			</tr>
			<tr>
				<td>验证码:</td>
				<td>
					<input id="loginCode" type="text" value="" style="width:80px;"/>
					<img id="loginCodeImg" src="/validateCode?"+Math.random() 
						style="width:100px; height:30px; cursor:pointer;"
						title="点击更换验证码"
						onclick="clickLoginCodeUpdate()" 
					/>
				</td>
			<tr>
			<tr>
				<td></td>
				<td>
					<input id="loginButton" type="button" value="登陆" onclick="clickLoginButton()"/>
				</td>
			</tr>
		</table>
	</div>
</body>
<script type="text/javascript">
	<%--点击更新验证码--%>
	function clickLoginCodeUpdate(){
		$("#loginCodeImg").attr("src","/validateCode?"+Math.random());
	}
	
	<%--点击登录按钮--%>
	function clickLoginButton(){
		var dataSet = {
			"userName":$("#userName").val(),
			"userPass":$("#userPass").val(),
			"validateCode":$("#loginCode").val(),
		};
		
		tool.ajax({
			requestUrl:"/admin/ajax?action=login",
			overtimeUrl:"/admin/login",
			dataSet:dataSet,
			success:function(msg){
				if(msg.stateCode == "validateCode_isnull"){
					alert("请填写验证码");
				}
				else if(msg.stateCode == "validateCode_error"){
					alert("验证码填写错误");
					<%--调用更新验证码--%>
					clickLoginCodeUpdate();
				}
				else if(msg.stateCode == "userPass_error"){
					alert("用户密码错误");
					<%--调用更新验证码--%>
					clickLoginCodeUpdate();
				}
				<%--成功--%>
				else if(msg.stateCode == "success"){
					window.location.href = "/admin/index";
				}
			}
		});
	}
</script>
</html>
